<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>开关灯</title>
    <style>
        div {
            width: 100%;
            height: 250px;
            text-align: center;
            position: relative;
        }

        div button {
            position: absolute;
            top: 25%;
            left: 50%;
            transform: translate(-50%, -50%);
            font-size: 20px;
            width: 150px;
            height: 50px;
        }

        #light {
            width: 200px;
            height: 250px;
            margin-top: 5%;
        }
    </style>
</head>

<body>
    <div id="app">
        <div>
            <!-- 按钮点击事件 -->
            <button @click="
                lightImage = isLightOn ? lightOffImage : lightOnImage; 
                buttonText = isLightOn ? '开灯' : '关灯'; 
                isLightOn = !isLightOn
            ">
                {{ buttonText }}
            </button>
            <img id="light" :src="lightImage" alt="Light">
        </div>
    </div>
    <script src="./js/vue.global.js"></script>
    <script>
        Vue.createApp({
            data() {
                return {
                    // 默认开灯
                    isLightOn: true,
                    lightOnImage: './img/on.jpg',  // 替换为你的灯开图片路径
                    lightOffImage: './img/off.jpg',  // 替换为你的灯关图片路径
                    lightImage: './img/on.jpg',  // 初始图片路径
                    buttonText: '关灯'  // 初始按钮文本
                }
            }
        }).mount('#app')
    </script>
</body>

</html>